//
//  StringUtils.m
//  uteped_sdk
//
//  Created by mateng on 2024/2/28.
//

#import <CommonCrypto/CommonDigest.h>
#import "StringUtils.h"

@implementation StringUtils

+ (nonnull NSString *)insertStringAll:(nonnull NSString *)originalStr insertStr:(nonnull NSString *)insertStr  position:(NSInteger)position {
    NSMutableString *resultStr = [[NSMutableString alloc] init];
    
    NSInteger segments = originalStr.length / position;
    
    for (NSInteger i = 0;i < segments; i++) {
        NSString *sub = [originalStr substringWithRange:NSMakeRange(i * position, position)];
        if (i < segments) {
            [resultStr appendString:sub];
            if (i < segments - 1)
                [resultStr appendString:insertStr];
        }
    }
    
    // 输出结果
    
    return resultStr;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ (NSString *)md5String:( NSString *)str {
    const char *myPasswd = [str UTF8String ];
    unsigned char mdc[16];
    CC_MD5 (myPasswd, (CC_LONG) strlen (myPasswd), mdc);
    NSMutableString *md5String = [ NSMutableString string ];
    for ( int i = 0 ; i< 16 ; i++) {
        [md5String appendFormat : @"%02x" ,mdc[i]];
    }
    
    return md5String;
}
#pragma clang diagnostic pop

@end
